package com.jds.test.bio.p5;

/**
 * base p3 增加缓冲区
 * https://www.cnblogs.com/silyvin/articles/12011037.html
 * Created by joyce on 2019/11/26.
 */


import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;


public class Client {

    public static final int PORT = 12123;
    public static final int BUFFER_SIZE = 1024;

    public static void main(String []f) throws IOException {
        new Client().client();
    }

    //客户端代码
    public void client() throws UnknownHostException, IOException{

        final String s1 = "49.235.75.155";// tx
        final String s2 = "localhost";
        final String s3 = "39.100.99.222";// al
        byte[] buffer;
    //    Socket s = new Socket(s1,PORT);//创建socket连接
        Socket s = new Socket();
        System.out.println(s.getReceiveBufferSize());
        System.out.println(s.getSendBufferSize());
        s.setReceiveBufferSize(100);
        s.setSendBufferSize(100);
        s.connect(new InetSocketAddress(s1, PORT));

//        s.getOutputStream().write(new byte[BUFFER_SIZE]);
//        s.getOutputStream().flush();
        int i = s.getInputStream().read(buffer = new byte[BUFFER_SIZE]);
        System.out.println(new String(buffer,0,i));
    }
}